package com.hospital.ssm.util;



import com.hospital.ssm.model.Medicine;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Aspect
public class CustomAspect {

    //医生添加人数
    public static int doctorinsertcount;
    //医生减少人数
    public static int doctordeletecount;

    //药品添加数
    public static Map medicineinsertcount;

    //药品减少数
    public static Map medicinedeletecount;


    public static Map medicineincomecount;


    //人力资源增长
    @After("execution(* com.hospital.ssm.service.serviceimpl.DoctorServiceimpl.insert(..))")
    public void countDoctorInsert(){
        doctorinsertcount += 1;
    }

    //人力资源减少
    @After("execution(* com.hospital.ssm.service.serviceimpl.DoctorServiceimpl.delete(..))")
    public void countDoctorDelete(){
        doctordeletecount += 1;
    }

    //药品增长
    @After("execution(* com.hospital.ssm.service.serviceimpl.MedicineServiceImpl.addMedicine(..))")
    public void countMedicineInsert(JoinPoint jp) {
        Object[] obj = jp.getArgs();
        for (int i = 0; i < obj.length; i++) {
            Medicine medicine = (Medicine) obj[i];
            medicineinsertcount.put(medicine.getmName(),medicine.getmNumber());
        }
    }

    //药品减少
/*    @After("execution(* com.hospital.ssm.service.serviceimpl.MedicineServiceImpl.addMedicine(..))")
    public void countMedicineDelete(JoinPoint jp) {
        Medicine medicine = (Medicine) jp.getTarget();
        medicineinsertcount.put(medicine.getmName(),medicine.getmNumber());
    }*/

    //服务收入
    @After("execution(* com.hospital.ssm.service.serviceimpl.MedicineServiceImpl.addMedicine(..))")
    public void countServiceInsert(){

    }

    //药品收入
    @After("execution(* com.hospital.ssm.service.serviceimpl.MedicineServiceImpl.addMedicine(..))")
    public void countMedicalInsert(JoinPoint jp){
        Medicine medicine = (Medicine) jp.getTarget();
        medicineincomecount.put(medicine.getmName(),medicine.getmPrice() * medicine.getmNumber());

    }

}
